package com.zcbl.toolkit.util;


import org.apache.commons.codec.binary.Hex;
import org.springframework.util.Assert;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author he peng
 * @create 2018/4/25 16:43
 * @see
 */
public class Md5Utils {

    private static MessageDigest MD5_MESSAGE_DIGEST;

    static {
        try {
            MD5_MESSAGE_DIGEST = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {

        }
    }

    public static String md5EncodeHex(byte[] data , int offset, int len) {
        Assert.notNull(data , "data == null");
        MD5_MESSAGE_DIGEST.update(data , offset , len);
        return Hex.encodeHexString(MD5_MESSAGE_DIGEST.digest());
    }

}
